#define _CRT_SECURE_NO_WARNINGS
#include<iostream>

//https://www.luogu.com.cn/problem/P2580
using namespace std;
const int N = 5e5 + 10;
int tr[N][26], e[N];
int n, m, idx;


void insert(string& s)
{
	int cur = 0;
	for (auto ch : s)
	{
		int path = ch - 'a';
		if (tr[cur][path] == 0)tr[cur][path] = ++idx;
		cur = tr[cur][path];
	}
	e[cur]++;
}

int find(string& s)
{
	int cur = 0;
	for (auto ch : s)
	{
		int path = ch - 'a';
		if (tr[cur][path] == 0)return 0;
		cur = tr[cur][path];
	}
	if (e[cur] > 0)
	{
		int t = e[cur];
		e[cur] = -1;
		return t;
	}
	return e[cur];
}


int main()
{
	cin >> n;
	while (n--)
	{
		string s;
		cin >> s;
		insert(s);
	}
	cin >> m;
	while (m--)
	{
		string s;
		cin >> s;
		int ret = find(s);
		if (ret > 0)cout << "OK" << endl;
		else if (ret == -1)cout << "REPEAT" << endl;
		else cout << "WRONG" << endl;
	}
	return 0;
}